/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('viapi', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model CancelWaitingAsyncJobRequest {
  jobId?: string(name='JobId', example='E75FE679-0303-4DD1-8252-1143B4FA8A27'),
}

model CancelWaitingAsyncJobResponseBody = {
  httpCode?: string(name='HttpCode', example='200'),
  message?: string(name='Message', example='Cancel job success'),
  requestId?: string(name='RequestId', example='43A0AEB6-45F4-4138-8E89-E1A5D63200E3'),
  success?: boolean(name='Success', example='true'),
}

model CancelWaitingAsyncJobResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: CancelWaitingAsyncJobResponseBody(name='body'),
}

async function cancelWaitingAsyncJobWithOptions(request: CancelWaitingAsyncJobRequest, runtime: Util.RuntimeOptions): CancelWaitingAsyncJobResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.jobId)) {
    body['JobId'] = request.jobId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'CancelWaitingAsyncJob',
    version = '2023-01-17',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function cancelWaitingAsyncJob(request: CancelWaitingAsyncJobRequest): CancelWaitingAsyncJobResponse {
  var runtime = new Util.RuntimeOptions{};
  return cancelWaitingAsyncJobWithOptions(request, runtime);
}

model GetAsyncJobResultRequest {
  jobId?: string(name='JobId', example='E75FE679-0303-4DD1-8252-1143B4FA8A27'),
}

model GetAsyncJobResultResponseBody = {
  data?: {
    errorCode?: string(name='ErrorCode', example='InvalidParameter'),
    errorMessage?: string(name='ErrorMessage', example='product is not active'),
    jobId?: string(name='JobId', example='B6590005-5E7C-4A25-8F97-4479888D8271'),
    result?: string(name='Result', example='{\\"pointCloudUrl\\":\\"http://virutalbuy-public.oss-cn-hangzhou.aliyuncs.com/MultiviewStereo/83e2fcec-02e1-4522-8680-92f532956e2c/cas_input.ply\\"}'),
    status?: string(name='Status', example='PROCESS_SUCCESS'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='E335106F-9F96-491D-AEB3-1610F8545968'),
}

model GetAsyncJobResultResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetAsyncJobResultResponseBody(name='body'),
}

async function getAsyncJobResultWithOptions(request: GetAsyncJobResultRequest, runtime: Util.RuntimeOptions): GetAsyncJobResultResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.jobId)) {
    body['JobId'] = request.jobId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetAsyncJobResult',
    version = '2023-01-17',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getAsyncJobResult(request: GetAsyncJobResultRequest): GetAsyncJobResultResponse {
  var runtime = new Util.RuntimeOptions{};
  return getAsyncJobResultWithOptions(request, runtime);
}

model QueryAsyncJobListRequest {
  endTime?: string(name='EndTime', example='2023-01-04 23:00:00'),
  jobId?: string(name='JobId', example='E75FE679-0303-4DD1-8252-1143B4FA8A27'),
  pageNum?: string(name='PageNum', example='1'),
  pageSize?: string(name='PageSize', example='20'),
  popApiName?: string(name='PopApiName', example='RecognizeIdentityCard'),
  popProduct?: string(name='PopProduct', example='ocr'),
  startTime?: string(name='StartTime', example='2023-01-04 00:00:00'),
  status?: string(name='Status', example='PROCESS_SUCCESS'),
}

model QueryAsyncJobListResponseBody = {
  data?: {
    currentPage?: int32(name='CurrentPage', example='1'),
    pageSize?: int32(name='PageSize', example='20'),
    result?: [ 
      {
        callerParentId?: string(name='CallerParentId', example='1850343078585779'),
        endTime?: string(name='EndTime', example='2023-01-04 17:18:44'),
        gmtCreate?: string(name='GmtCreate', example='2023-01-04 17:18:44'),
        jobId?: string(name='JobId', example='49E2CC28-ED1D-4CC5-854D-7D0AE2B20976'),
        popApiName?: string(name='PopApiName', example='DetectVideoShot'),
        popProduct?: string(name='PopProduct', example='videorecog'),
        startTime?: string(name='StartTime', example='2023-01-04 17:18:44'),
        status?: string(name='Status', example='PROCESS_SUCCESS'),
      }
    ](name='Result'),
    totalPage?: int32(name='TotalPage', example='2'),
    totalRecord?: int32(name='TotalRecord', example='22'),
  }(name='Data'),
  httpCode?: string(name='HttpCode', example='200'),
  message?: string(name='Message', example='success'),
  requestId?: string(name='RequestId', example='43A0AEB6-45F4-4138-8E89-E1A5D63200E3'),
  success?: boolean(name='Success', example='true'),
}

model QueryAsyncJobListResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: QueryAsyncJobListResponseBody(name='body'),
}

async function queryAsyncJobListWithOptions(request: QueryAsyncJobListRequest, runtime: Util.RuntimeOptions): QueryAsyncJobListResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.endTime)) {
    body['EndTime'] = request.endTime;
  }
  if (!Util.isUnset(request.jobId)) {
    body['JobId'] = request.jobId;
  }
  if (!Util.isUnset(request.pageNum)) {
    body['PageNum'] = request.pageNum;
  }
  if (!Util.isUnset(request.pageSize)) {
    body['PageSize'] = request.pageSize;
  }
  if (!Util.isUnset(request.popApiName)) {
    body['PopApiName'] = request.popApiName;
  }
  if (!Util.isUnset(request.popProduct)) {
    body['PopProduct'] = request.popProduct;
  }
  if (!Util.isUnset(request.startTime)) {
    body['StartTime'] = request.startTime;
  }
  if (!Util.isUnset(request.status)) {
    body['Status'] = request.status;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'QueryAsyncJobList',
    version = '2023-01-17',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function queryAsyncJobList(request: QueryAsyncJobListRequest): QueryAsyncJobListResponse {
  var runtime = new Util.RuntimeOptions{};
  return queryAsyncJobListWithOptions(request, runtime);
}

